<?php
require_once('../phplib/include.inc.php');

class DoDeleteType{
	public function DoDelete(){
		Util::ValidateRight(array(1,5),'or');
		if(!isset($_REQUEST['tid'])) PageBase::Error('非法访问.');
		$tid = intval($_REQUEST['tid']);
		/* @var $db DbMySQL */
		$db = getDb();
		$db->connect();
		$tname = $db->fetchScalar("SELECT tname FROM type_t WHERE tid=$tid");
		$re = $db->fetch("SELECT * FROM product_t WHERE tid=$tid");
		if(count($re) > 0){
			PageBase::Error('请先删除属于该车辆类型的焊接数据，再删除车辆类型.');
		}
		$re = $db->execute("DELETE FROM type_t WHERE tid=$tid");
		if($re === false){
			PageBase::Error('删除车辆类型时出错，未知错误，请与技术人员联系');
		}
		Util::AddLog('删除车辆类型：'.$tname.' 车辆类型的id为:'.$tid);
		PageBase::Go('../home/typeadmin.php');
	}
}
$dodeletetype = new DoDeleteType();
$dodeletetype->DoDelete();
?>